'use strict'

class uploadapp {

  constructor () {
    this.param = '/'
  }

  async get (c){
    
    c.send('true',200)

  }

  async options (c) {
    c.send('option ture',200)
  }

  async post (c) {
   
    let f = c.body.file.image;
    console.log(f)
    let ext_name = c.helper.extName(f.filename)

    let fname = `${c.body.appname}${ext_name}`

    //移动文件到目标路径
    await c.moveFile(f, `../public/image/ico/${fname}`)

    try {

      let datas = {
        appname:c.body.appname,
        image:c.body.image
      }

      let data = await c.service.model.funcapp.insert(datas);
      c.send(data,200)

    } catch (err) {

      console.error(err)
      c.send('login failed', 400)

    }
  }

}
module.exports = uploadapp